package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.example.demo.common.Result;
import com.example.demo.entity.Dan;
import com.example.demo.service.DanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wms
 * @since 2023-02-07
 */

@RestController
@RequestMapping("/dan")
public class DanController {

    @Autowired
    private DanService danService;

    @GetMapping("/list")
    public List<Dan> list() {
        return danService.list();
    }

    //新增
    @PostMapping("/save")
    public Result save(@RequestBody Dan dan) {
        return danService.save(dan) ? Result.suc() : Result.fail();
    }

    //更新
    @PostMapping("/update")
    public Result update(@RequestBody Dan dan) {
        return danService.updateById(dan) ? Result.suc() : Result.fail();
    }

    //删除
    @GetMapping("/del")
    public Result del(@RequestParam String id) {
        return danService.removeById(id) ? Result.suc() : Result.fail();
    }

    //修改
    @PostMapping("/mod")
    public boolean mod(@RequestBody Dan dan) {
        return danService.updateById(dan);
    }

    //新增或修改
    @PostMapping("/saveOrMod")
    public boolean saveOrMod(@RequestBody Dan dan) {
        return danService.saveOrUpdate(dan);
    }
}

